package com.qf.config;

import com.qf.job.MonitorQueueMessageJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 任务初始化配置
 */
@Configuration
public class MonitorQueueConfig {


    /**
     * 配置任务的执行周期
     * @return
     */
    @Bean
    public JobConfiguration monitorQueueJob(){
        JobConfiguration jobConfig = JobConfiguration
                .newBuilder("MonitorQueueMessageJob", 1)
                .cron("0,30 * * * * ?")
                .build();

        return jobConfig;
    }

    /**
     * 配置到ScheduleJobBootstrap
     */
    @Bean
    public ScheduleJobBootstrap monitorQueueBootstrap(CoordinatorRegistryCenter zookeeperRegistryCenter,
                                                      MonitorQueueMessageJob monitorQueueMessageJob,
                                                      JobConfiguration monitorQueueJob){

        ScheduleJobBootstrap jobBootstrap = new ScheduleJobBootstrap(
                zookeeperRegistryCenter,
                monitorQueueMessageJob,
                monitorQueueJob);

        jobBootstrap.schedule();
        return jobBootstrap;
    }

//    @Bean(initMethod = "schedule")
//    public ScheduleJobBootstrap schedulerJobBootstrap(CoordinatorRegistryCenter registryCenter,
//                                                      MyElasticJob myElasticJob,
//                                                      JobConfiguration configuration){
//        ScheduleJobBootstrap scheduleJobBootstrap = new ScheduleJobBootstrap(
//                registryCenter,
//                myElasticJob,
//                configuration);
//
//        return scheduleJobBootstrap;
//    }



}
